package hypeerweb;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashSet;

import network.LocalObjectId;
import network.ObjectDB;
import network.PeerCommunicator;
import network.PortNumber;

public class HyPeerWebSegmentCreator {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		LocalObjectId localHyPeerWebId = createHyPeerWeb(49205);
	}

	public static LocalObjectId createHyPeerWeb(int port) {
		PeerCommunicator.createPeerCommunicator(new PortNumber(port));
		HyPeerWebSegment hypeerweb = HyPeerWebSegment.getSingleton();
		hypeerweb.addNode(new Node(0));
		hypeerweb.addToHyPeerWeb(0, null);

		try {
			System.out.println("Machine Name: "
					+ InetAddress.getLocalHost().getHostAddress());
			System.out.println("Machine Port: "
					+ PortNumber.getApplicationsPortNumber().getValue());
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		System.out.println("Local HyPeerWeb: "
				+ hypeerweb.getLocalObjectId().toString());
		ObjectDB.getSingleton().dump();
		return hypeerweb.getLocalObjectId();
	}
	
	public static void MergeSegments(HyPeerWebSegment s1, HyPeerWebSegment s2) {
		s2.getNext().setPrev(s1.getPrev());
		s1.getPrev().setNext(s2.getNext());
		s2.setNext(s1);
		s1.setPrev(s2);
	}
}
